package com.dingwen.treasure.base.exception;


import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.base.pojo.vo.ResultGenerator;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;


/**
 * 　ExceptionHandler: 异常状态处理，策略模式实现（替代冗长的 instance of if 语句）
 * 　@author dingwen
 * 　@date 2022/5/14$
 */

@Component("java.lang.Exception")
public class BaseExceptionHandler<T> {

    /**
     * 根据异常构建统一返回结果
     *
     * @param exception
     * @return result
     */
    public Result<T> buildResultByException(Exception exception) {
        return ResultGenerator.genFailureResult(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value());
    }
}
